/*
* berton
*/
package com.pitop.material.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

import com.pitop.material.api.MaterialBrandFeignApi;
import com.pitop.core.exceptions.MaterialBrandException;
import com.pitop.core.exceptions.BaseException;
import com.pitop.core.entity.Page;
import com.pitop.material.entity.MaterialBrand;


/**
 * 材料品牌
 * @author berton
 */
@Service("materialBrandSVImpl")
@Slf4j
public class MaterialBrandSVImpl {

    @Autowired
    private MaterialBrandFeignApi materialBrandFeignApi;

    /**
     * 加载一个对象MaterialBrand
     * @param id * @param code 品牌编码
     * @return MaterialBrand
     */
    public MaterialBrand load(java.lang.Long id,java.lang.String code) {
        if(id==null&&code==null){
            throw new MaterialBrandException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        return materialBrandFeignApi.load(id,code);
    }
    /**
     * 加载一个对象MaterialBrand 通过id
     * @param id 
     * @return MaterialBrand
     */
    public MaterialBrand loadById(java.lang.Long id) {
        if(id==null){
            throw new MaterialBrandException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        return materialBrandFeignApi.loadById(id);
    }

    /**
     * 加载一个对象MaterialBrand 通过code
     * @param code 品牌编码
     * @return MaterialBrand
     */
    public MaterialBrand loadByCode(java.lang.String code) {
        if(code==null){
            throw new MaterialBrandException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        return materialBrandFeignApi.loadByCode(code);
    }


    /**
     * 删除对象MaterialBrand
     * @param id * @param code 品牌编码
     * @return MaterialBrand
     */
    
    public void delete(java.lang.Long id,java.lang.String code) {
        if(id==null&&code==null){
            throw new MaterialBrandException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        materialBrandFeignApi.delete(id,code);
    }



    /**
     * 查询MaterialBrand分页
     *
     * @param materialBrand  对象
     * @param curPage 当前页
     * @param pageSize 分页条数
     * @return List<MaterialBrand>
     */
    public List<MaterialBrand> list(MaterialBrand materialBrand, int curPage,int pageSize) {
        return materialBrandFeignApi.list(materialBrand, curPage,pageSize);
    }

    /**
     * 查询MaterialBrand分页
     *
     * @param id  * @param code  品牌编码
     * @param curPage 当前页
     * @param pageSize 分页条数
     * @return List<MaterialBrand>
     */
    public List<MaterialBrand> list(java.lang.Long id,java.lang.String code,int curPage, int pageSize) {
        if (curPage < 0) {
           curPage = 1;
        }

        if (pageSize < 0) {
            pageSize = Page.limit;
        }

        MaterialBrand materialBrand=new MaterialBrand();
        materialBrand.setId(id);
        materialBrand.setCode(code);

        return materialBrandFeignApi.list(materialBrand,curPage,pageSize);
    }


    public int count(java.lang.Long id,java.lang.String code) {
        return materialBrandFeignApi.count(id,code);
    }


    public int count(MaterialBrand materialBrand) {
        return materialBrandFeignApi.count(materialBrand);
    }


    /**
     * 保存
     *
     * @param materialBrand 实体
     * @throws BaseException
     */
    public void save(MaterialBrand materialBrand) {
        if(materialBrand==null){ throw new MaterialBrandException(BaseException.BaseExceptionEnum.Ilegal_Param);}
        materialBrandFeignApi.build(materialBrand);
    }

    /**
     * 更新
     *
     * @param materialBrand 实体
     * @throws BaseException
     */
    public void modify(MaterialBrand materialBrand) {
        if(materialBrand==null){ throw new MaterialBrandException(BaseException.BaseExceptionEnum.Ilegal_Param);}
        materialBrandFeignApi.modify(materialBrand);
    }

}
